//ProxyRoom.java
package proxy.wisereference;

/**
 *@author:youtubezou
 *@version:2012-7-25
 */
public class ProxyRoom implements Room {
	private SafeRoom room = new SafeRoom();
	private AccessChecker accessChecker = new AccessChecker();
	private Logger logger = new Logger();

	@Override
	public boolean enterRoom(Person person) {
		if(accessChecker.isValidUser(person.getId())){
			room.setPerson(person);
			logger.writeToStdout(person.getName() + " entered!");
			return true;
		} else {
			logger.writeToStdout(person.getName() + " is forbidden!");
			return false;
		}
	}

	@Override
	public Subject getSubject() {
		Subject subject = room.getSubject();
		
		logger.writeToStdout(room.getPerson().getName() + " take " + subject);
		
		return subject; 
	}

	@Override
	public void exitRoom() {
		logger.writeToStdout(room.getPerson().getName() + " get out of room!");
		room.exitRoom();
	}
}
